package com.sinosoft.tcmcp.system.web.dto;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.sinosoft.framework.core.api.domain.IdentityInformationEntity;
import com.sinosoft.framework.core.common.utils.ajax.ObjectUtil;

/**
 * 人员身份信息传输类
 * @author xiaoxiong
 *
 */
public class IdentityInfomationData implements Serializable{

	private static final long serialVersionUID = 1L;
	
	private String id;	//	身份编号
	private String name;	//	名字
	private String gender;	//	性别
	private Date birthday;	//	出生日期
	private String birthdate; //出生日期字符串中转变量
	private String telephone;	//	联系电话
	private String oid;	//	机构编号
	private String cardno;	//	证件号码
	private String job;	//	职业
	private String email;	//	邮箱
	private String address;	//	住址
	private String position;	//	职位
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getGender() {
		return gender;
	}
	public void setGender(String gender) {
		this.gender = gender;
	}
	public Date getBirthday() {
		return birthday;
	}
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	public String getBirthdate() {
		return birthdate;
	}
	public void setBirthdate(String birthdate) {
		this.birthdate = birthdate;
	}
	public String getTelephone() {
		return telephone;
	}
	public void setTelephone(String telephone) {
		this.telephone = telephone;
	}
	public String getOid() {
		return oid;
	}
	public void setOid(String oid) {
		this.oid = oid;
	}
	public String getCardno() {
		return cardno;
	}
	public void setCardno(String cardno) {
		this.cardno = cardno;
	}
	public String getJob() {
		return job;
	}
	public void setJob(String job) {
		this.job = job;
	}
	public String getEmail() {
		return email;
	}
	public void setEmail(String email) {
		this.email = email;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getPosition() {
		return position;
	}
	public void setPosition(String position) {
		this.position = position;
	}

	/**
	 * 数据转换
	 * 实体类转传输类
	 * @param identityInformationEntity	身份信息实体
	 */
	public void toIdentityInformationData(IdentityInformationEntity identityInformationEntity) {
		ObjectUtil.oldToNew(this, identityInformationEntity, "serialVersionUID");
		SimpleDateFormat sdf =   new SimpleDateFormat( "yyyy-MM-dd" ); 
		if(this.birthday!=null){
			this.birthdate = sdf.format(this.getBirthday());
		}else{
			this.birthdate = "";
		}
	}
	
	/**
	 * 数据转换
	 * 传输类转实体类
	 * @return	身份信息实体
	 * @throws ParseException	日期转换异常
	 */
	public IdentityInformationEntity toEntity() throws ParseException{
		IdentityInformationEntity identityInformationEntity = new IdentityInformationEntity();
		if(this.birthday!=null){
			this.setBirthday(tobirthday(this.birthdate));
			ObjectUtil.oldToNew(identityInformationEntity, this, "serialVersionUID");
		}else{
			ObjectUtil.oldToNew(identityInformationEntity, this, "serialVersionUID");
		}
		return identityInformationEntity;
	}
	
	public Date tobirthday(String birthdate) throws ParseException{
		if(birthdate != null){
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
			Date date = sdf.parse(birthdate);
			return date;
		}else{
			return null ;
		}
	}
}
